package com.blinddate.dao.impl;

import java.util.List;

import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.blinddate.orm.BdCountry;
import com.blinddate.orm.BdProvince;

public class ProvinceDAO extends HibernateDaoSupport implements
		com.blinddate.dao.ProvinceDAO {

	@Override
	public boolean addProvinceDAO(BdProvince province) {
		boolean addSuccess = false;
		try{
			this.getHibernateTemplate().save(province);
			addSuccess = true; 
		}catch(Exception e){
			addSuccess = false;
		}
		return addSuccess;
	}

	@Override
	public boolean updateProvince(BdProvince province) {
		boolean updateSuccess = false;
		try{
			this.getHibernateTemplate().update(province);
			updateSuccess = true;
		}catch(Exception e){
			updateSuccess = false;
			e.printStackTrace();
		}
		return updateSuccess;
	}

	@Override
	public boolean deleteProvince(BdProvince province) {
		boolean deleteSuccess = false;
		try{
			this.getHibernateTemplate().delete(province);
			deleteSuccess = true;
		}catch(Exception e){
			deleteSuccess = false;
			e.printStackTrace();
		}
		return deleteSuccess;
	}

	@Override
	public List<BdProvince> getProvincesOfCountry(Integer countryId) {
		List<BdProvince> provinces = null;
		try{
			String queryCondition = "from BdProvince where id = ?";
			provinces = (List<BdProvince>)this.getHibernateTemplate().find(queryCondition, countryId);
		}catch(Exception e){
			provinces = null;
			e.printStackTrace();
		}
		return provinces;
	}

}
